#include <bits/stdc++.h>
using namespace std;
int T;
bool usec[100100],usep[100100],cp[100100];
int p[100100];
struct node{
	int d,v,a;
	double cx,cy;
}c[100100];
int main()
{
	freopen("detect.in","c",stdin);
	freopen("detect.out","w",stdout);
	cin>>T;
	for(int z=1;z<=T;z++)
	{
		memset(usep,0,sizeof(usep));
		memset(usec,0,sizeof(usec));
		memset(p,0,sizeof(p));
		int n,m,l,cnt1=0,cnt2=0;
		double V;
		cin>>n>>m>>l>>V;
		for(int i=1;i<=n;i++){
			cin>>c[i].d>>c[i].v>>c[i].a;
			if(c[i].v>V){
				c[i].cx=c[i].d;
				if(c[i].a>=0) c[i].cy=l;
				else c[i].cy=c[i].d+(1.0*V*V-1.0*c[i].v*c[i].v)/2.0/c[i].a-1e-5;
			}
			else if(c[i].v==V){
				if(c[i].a>0) {
					c[i].cx=c[i].d+1e-5;
					c[i].cy=l;
				}
				else c[i].cx=c[i].cy=0;
			}
			else {
				if(c[i].a>0){
					double ev=sqrt(c[i].v*c[i].v*1.0+2.0*c[i].a*(l-c[i].d));
					if(ev<=V) c[i].cx=c[i].cy=0;
					else {
						c[i].cx=c[i].d+1e-5+(1.0*V*V-c[i].v*c[i].v*1.0)/2.0/c[i].a;
						c[i].cy=l;
					}
				}
				else c[i].cx=c[i].cy=0;
			}
		}
		for(int i=1;i<=m;i++){
			cin>>p[i];
			int k=0;
			for(int j=1;j<=n;j++)
				if(c[j].cx<=p[i]&&p[i]<=c[j].cy){
					usep[i]++;
					//cp[i][++k]=j;
					usec[j]=1;
				}
		}
		sort(usep+1,usep+1+m);
		bool check[100100];
		for(int i=m;i>=1;i--)
		{
			if(usep[i]==1||usep[i]==0) break;
			for(int j=1;j<=usep[i];j++)
				check[cp[i][j]]=1;
				cnt2++;
			}
		}
		for(int i=1;i<=n;i++)
			if(check[i]==0&&usec[i]!=0) cnt2++;
		for(int i=1;i<=n;i++)
			if(usec[i]==1)
				cnt1++;
		for(int i=1;i<=m;i++)
			if(usep[i]==0) cnt2++;
		cout<<cnt1<<" "<<cnt2<<endl;
	}
	return 0;
}
